package com.taxshare.manager.controller;

import com.taxshare.manager.service.RoleResourceService;
import com.taxshare.manager.view.dto.RoleResourceDTO;
import com.taxshare.response.beans.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: RoleResourceController
 * @Description:
 * @author: luozhongyi
 * @date: 2021/1/28 10:43
 */
@RestController
@RequestMapping(value = "/roleResource")
@Api(tags = "角色资源信息")
public class RoleResourceController {
    @Autowired
    private RoleResourceService roleResourceService;

    /**
     * 获取资源树,资源分配,获取初始化资源集合
     */
    @GetMapping("/init/tree")
    @ApiOperation(value = "获取资源树", notes = "获取资源树")
    public Response getResourceTree() {
        return roleResourceService.initResourceTree();
    }


    /**
     * 获取当前职位的资源节点集合,用于前端展示
     */
    @GetMapping("/get/treeList")
    @ApiOperation(value = "获取当前角色的资源节点集合,用于前端展示", notes = "获取当前角色的资源节点集合,用于前端展示")
    public Response getResourceList(String positionCode) {
        return roleResourceService.getResourceTree(positionCode);
    }


    /**
     * 保存当前职能分配的资源
     */
    @PostMapping("/save/resource")
    @ApiOperation(value = "保存当前职能分配的资源", notes = "保存当前职能分配的资源")
    public Response saveResource(@RequestBody RoleResourceDTO pojo) {
        return roleResourceService.saveResource(pojo);
    }
}
